package com.haierp.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.haierp.mapper.SellerMapper;
import com.haierp.model.Seller;
import com.haierp.model.SellerType;
import com.haierp.service.ISellerService;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.SellerQueryVO;

/**
 * 
 * Title: SellerServiceImpl.java
 * Description: Implements ISellerService
 *
 * @author jc
 * Mar 18, 2017
 *
 */

@Service("sellerService")
public class SellerServiceImpl extends SuperServiceImpl<SellerMapper, Seller> implements ISellerService {

	@Autowired
	private SellerMapper sellerMapper;	
	
	@Override
	public Integer querySellersCount(SellerQueryVO sellerQueryVO)
	{
		return sellerMapper.querySellersCount(sellerQueryVO);
	}
	
	@Override
	public JsonPageResult<List<Seller>> querySellerList(SellerQueryVO sellerQueryVO) {
		JsonPageResult<List<Seller>> sellerResult = new JsonPageResult<>();
		
		Integer totalCount = sellerMapper.querySellersCount(sellerQueryVO);
		
		if ((null != totalCount) && (0L != totalCount)) {
			sellerResult.buildPage(totalCount, sellerQueryVO);
			
			List<Seller> sellers = sellerMapper.querySellers(sellerQueryVO);
			sellerResult.setData(sellers);			
		} else {
			List<Seller> sellers = new ArrayList<>();
			sellerResult.setData(sellers);
		}
		
		return sellerResult;
	}
	
	public void updateSellerTypeByTypeCode(SellerType sellerType) {
		sellerType.setGmtModify(new Date());
		
		sellerMapper.updateSellerTypeByTypeCode(sellerType);
	}
	
	@Override
	public Integer querySaleCountInOrder(Long salesId) {
		Integer totalCount = sellerMapper.querySaleCountInOrder(salesId);
		return totalCount;
	}
}
